package com.cskaoyan.controller;


import com.cskaoyan.bean.Category;
import com.cskaoyan.service.CategoryService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.CategoryVo;
import com.cskaoyan.vo.LevelVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 接口功能：品类
 *
 * @author chen11
 */

@RestController
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    //品类的list
    @RequestMapping("admin/category/list")
    public BaseRespVo selectCategoryList() {
        List<CategoryVo> categoryVos = categoryService.selectCategoryList();
        return BaseRespVo.ok(categoryVos);
    }

    //删除品类
    @RequestMapping("admin/category/delete")
    public BaseRespVo deleteCategory(@RequestBody CategoryVo categoryVo) {
        categoryService.deleteCategory(categoryVo);
        return BaseRespVo.ok();
    }

    //删除之后显示level1的品类
    @RequestMapping("admin/category/l1")
    public BaseRespVo selectCategoryL1() {
        List<LevelVo> levelVos = categoryService.selectCategoryL1();
        return BaseRespVo.ok(levelVos);
    }

    //更新品类
    @RequestMapping("admin/category/update")
    public BaseRespVo updateCategory(@RequestBody CategoryVo category) {
        categoryService.updateCategory(category);
        return BaseRespVo.ok();

    }

    //创建品类
    @RequestMapping("admin/category/create")
    public BaseRespVo createCategory(@RequestBody Category category) {

        categoryService.CreateCategory(category);
        return BaseRespVo.ok();

    }
}
